package com.minotauro.i18n.demo;

import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Locale;

import javax.swing.JComboBox;
import javax.swing.JFrame;

public class LanguageSelectionPanel extends JFrame{


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String[] languageStrings = {"Select language", "English", "Español", "Français"};
	private JComboBox<String> languageList;
	PanelTest pnlContent;

	public void init() {

		setLayout(new FlowLayout());

		languageList = new JComboBox<String>(languageStrings);
		languageList.setSelectedIndex(0);
		add(languageList);

		languageList.addItemListener(new ItemListener() {

			@Override
			public void itemStateChanged(ItemEvent arg0) {

				if(arg0.getStateChange() == ItemEvent.SELECTED){
					switch (languageList.getSelectedIndex()) 
					{
					case 1:
						Locale.setDefault(new Locale("en"));
						dispose();
						pnlContent = new PanelTest();
						break;

					case 2:
						Locale.setDefault(new Locale("es"));
						dispose();
						pnlContent = new PanelTest();
						break;

					case 3:
						Locale.setDefault(new Locale("fr"));
						dispose();
						pnlContent = new PanelTest();
						break;

					default:
						break;
					}				
				}
			}
		});
	}

	public LanguageSelectionPanel() {
		init();
	}
}
